package br.com.knowledge.persistence.hibernate.dao;

import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.classic.Session;

import static org.hibernate.criterion.Example.create;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;

import br.com.knowledge.persistence.hibernate.entities.AcdProjetolinguagem;

import org.hibernate.*;
import org.hibernate.criterion.*;

/**
 * A data access object (DAO) providing persistence and search support for
 * AcdProjetolinguagem entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see br.com.knowledge.persistence.hibernate.entities.AcdProjetolinguagem
 * @author MyEclipse Persistence Tools
 */

public class AcdProjetolinguagemDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(AcdProjetolinguagemDAO.class);

	// property constants

	public void save(AcdProjetolinguagem transientInstance) {
		log.debug("saving AcdProjetolinguagem instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(AcdProjetolinguagem persistentInstance) {
		log.debug("deleting AcdProjetolinguagem instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public AcdProjetolinguagem findById(java.lang.Integer id) {
		log.debug("getting AcdProjetolinguagem instance with id: " + id);
		try {
			AcdProjetolinguagem instance = (AcdProjetolinguagem) getSession()
					.get(
							"br.com.knowledge.persistence.hibernate.entities.AcdProjetolinguagem",
							id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	
	public List<AcdProjetolinguagem> findByProjeto(java.lang.Integer id) {
		log.debug(" AcdProjetolinguagem instance with cad_projeto: " + id);
		try {

			String queryString = "from AcdProjetolinguagem where cad_projeto_id = "+id;
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
	
	public void deleteById(AcdProjetolinguagem persistentInstance) {
		log.debug("deleting AcdProjetolinguagem instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	
/*
	public boolean deleteByProjeto(java.lang.Integer id) {
		log.debug("deleting AcdProjetolinguagem by projeto");
		try {	
			 String hql = "delete AcdProjetolinguagem where cad_projeto_id = "+id;
		     //Query query = getSession().createQuery("delete AcdProjetolinguagem where cad_projeto_id = "+id);
		     Session query = (Session) getSession().createQuery("delete AcdProjetolinguagem where cad_projeto_id = "+id);
		     int rowCount = ((Query) query).executeUpdate();
		     query.getTransaction().commit();
		     if (rowCount!=-1){
		    	 return true;
		     }else{
		    	 return false;
		     }
			
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
*/
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding AcdProjetolinguagem instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from AcdProjetolinguagem as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findAll() {
		log.debug("finding all AcdProjetolinguagem instances");
		try {
			String queryString = "from AcdProjetolinguagem";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public AcdProjetolinguagem merge(AcdProjetolinguagem detachedInstance) {
		log.debug("merging AcdProjetolinguagem instance");
		try {
			AcdProjetolinguagem result = (AcdProjetolinguagem) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(AcdProjetolinguagem instance) {
		log.debug("attaching dirty AcdProjetolinguagem instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(AcdProjetolinguagem instance) {
		log.debug("attaching clean AcdProjetolinguagem instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}